package org.example.controller;


import cn.dev33.satoken.stp.StpUtil;
import org.example.common.entity.Menu;
import org.example.entity.Result;
import org.example.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/menu")
public class MenuController {


    @Autowired
    private MenuService menuService;

    //查询当前用户的菜单
    @PostMapping("/listByUserId")
    public Result listByUserId(){
        return Result.success(menuService.listByUserId(StpUtil.getLoginIdAsLong()));
    }

    @GetMapping("/list")
    public Result list(){
        return Result.success(menuService.selectAllMenus());
    }

    // 新增菜单
    @GetMapping("/add")
    public Result add(Menu menu){
        return Result.success(menuService.insertMenu(menu));
    }
    @PostMapping("/save")
    public Result save(@RequestBody Menu menu){
        return Result.success(menuService.updateMenu(menu));
    }

    @GetMapping("/delete")
    public Result delete(String id){
        return Result.success(menuService.deleteMenu(id));
    }


}
